[#28420] Fix type inference for closures over local variables#39210
[#28420] Fix type inference for closures over local variables#39210lakshitbahl wants to merge 1 commit into
Conversation
|
Warning Gemini encountered an error creating the summary. You can try again by commenting |
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
0a8d1ab to
a831843
Compare
|
Fixes closure inference on Python ≤3.12 and narrows testLocalClosure's skip from unconditional to 3.13+ only. On 3.13+, MAKE_FUNCTION no longer takes a closure flag (closures attach via SET_FUNCTION_ATTRIBUTE) and the emulation of that path has pre-existing bugs (FunctionType called without a closure for freevar-carrying code; set_function_attribute uses func.code/func.globals/func.name instead of code/globals/name), so emulation-dependent tests are gated to <3.13. Real-closure inference (validated by the un-gated tests) works on all versions including 3.14. |
|
Assigning reviewers: R: @claudevdm for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
###Description:
This PR resolves closure-related type inference regressions (see #28420) and restores compatibility with Python 3.11+ opcode changes. It introduces two distinct fixes under a unified closure-handling improvement, allowing us to un-skip testLocalClosure.
Type-vs-Value Cell Confusion
Prevents the inference engine from confusing synthetic inferred types with real runtime closure values. Introduces the _TypeInCell marker class to safely wrap, track, and unwrap inferred types within the frame emulation, ensuring strict isolation from actual Python cell contents.
Python 3.11+ Shared-Slot Indexing
Fixes LOAD_CLOSURE and LOAD_DEREF indexing for Python 3.11 and newer. Replaces the legacy arg -= len(co_varnames) arithmetic, which broke when captured parameters shared a slot in the new unified localsplus array with version-aware slot-name resolution. This correctly maps variables and prevents out-of-bounds IndexError exceptions that were previously being swallowed by the safe-mode execution and degraded to Any.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.